# import time

# # def time1(fn):
# #   star_time=time.time()
# #   fn()
# #   end_time=time.time()
# #   print(end_time-star_time)

# # def hsys():
# #   time.sleep(3)

# # time1(hsys)

# def time1(fn):   #fn=hsys
#     def inner():   #把hsys里的参数调入
#         star_time=time.time()
#         fn()
#         end_time=time.time()
#         print(end_time-star_time)
#     return inner

# @time1
# def hsys():
#     print('开始')
#     time.sleep(3)
#     print('结束')


# hsys()

# #__________高级装饰器____________
# def can_play(clock):
#     print('最外层的函数被调用了,clock={}'.format(clock))
#     def handle_action(fn):   #can_play()自动调用这个

#         def do_action(name,game):
#             fn(name,game)
#         return do_action
#     return handle_action

# @can_play(15)
# def play_game(name,game):
#     print(name+'正在玩'+game)

# play_game('小王','王者农药')


# #__________迭代器____________(对象)
# iter   next
# 可迭代对象 list/tuple/dict/set/range/filter/map
# for  in
# class Foo():
#     def __next__(self):
#         return 1


# class Demo():
#     def __init__(self, x):
#         self.x = x
#         self.count=0

    # def __iter__(self):
    #     f=Foo()   #TypeError: iter() returned non-iterator of type 'Foo'
    #     return f  #返回对象必须是个迭代器对象

    # def __iter__(self):
    #               # TypeError: iter() returned non-iterator of type 'Foo'
    #     return self  # 返回对象必须是个迭代器对象

    # def __next__(self):
    #     self.count += 1
    #     if self.count <= self.x:
    #         return self.count-1
    #     else:
    #         raise StopIteration #停止迭代器


# d = Demo(10)

# for each in d:
#     print(each)

# isinstance()判断是不是类创建出来的

# i=iter(d)
# print(next(i))
# print(next(i))
# print(next(i))
# print(next(i))


# #__________生成器____________
# x=[i for i in range(8)]   列表推导式
# x=(i for i in range(8)) #生成器
# print(x)
# for m in x:
#     print(m)

def my_gen(n):
    i=0
    while i<n:
        i+=1
        yield i
G = my_gen(10)
print(next(G))
print(next(G))
print(next(G))
print(next(G))